import request from "@/utils/request";
import type { MachineTunnelDTO, MachineTunnelSaveCmd, PageDTO, R } from "@/types";
import { MachineTunnelPageQry } from "@/types";

function getMachineTunnelPage(qry: MachineTunnelPageQry): Promise<R<PageDTO<MachineTunnelDTO>>> {
  return request.get("/api/machine-tunnel/page", { params: qry });
}

function getMachineTunnel(id: string): Promise<R<MachineTunnelDTO>> {
  return request.get("/api/machine-tunnel/get-by-id", { params: { id } });
}

function saveMachineTunnel(cmd: MachineTunnelSaveCmd): Promise<R<string>> {
  return request.post("/api/machine-tunnel/save", cmd);
}

function deleteMachineTunnel(id: string): Promise<R<string>> {
  return request.post("/api/machine-tunnel/delete", {}, { params: { id } });
}

function startMachineTunnel(id: string): Promise<R<string>> {
  return request.post("/api/machine-tunnel/start",{}, { params: { id } } );
}

function stopMachineTunnel(id: string): Promise<R<string>> {
  return request.post("/api/machine-tunnel/stop", {},{ params: { id } });
}

export default {
  getMachineTunnelPage,
  getMachineTunnel,
  saveMachineTunnel,
  deleteMachineTunnel,
  startMachineTunnel,
  stopMachineTunnel
};
